VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsPrinting"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private cmdReportHeader As New ADODB.Command
Private cmdReportDetail As New ADODB.Command
Private cmdReportDetail2 As New ADODB.Command
Private cmdRptCompany As New ADODB.Command
Private rsReportHeader As New ADODB.Recordset
Private rsReportDetail As New ADODB.Recordset
Private rsReportDetail2 As New ADODB.Recordset
Private rsRptCompany As New ADODB.Recordset
Private rptTransID As String
Private rspHeader As String
Private rspDetail As String
Private rspDetail2 As String
Private rspComp As String


Public Sub PrintReceipt(cTransID As String)

Dim rptPrint As CRAXDRT.Report
Dim ReportApp As New CRAXDDRT.Application

On Error GoTo TheSource

Dim cSubRptName As String
Dim cSubRptCmp As String
    
    rptTransID = cTransID
        
    Select Case cModule
        Case "Sales_Order"
            cReceiptName = "Sales_Order_Trans"
            cSubRptName = "SO_Details"
            rspHeader = "rsp_Transaction_SO"
            rspDetail = "rsp_Transaction_SO_Details"
        
        Case "Basic_Sales_Order"
            cReceiptName = "BASIC_Sales_Order_Trans"
            cSubRptName = "SO_Details"
            rspHeader = "rspBasic_Transaction_SO"
            rspDetail = "rspBasic_Transaction_SO_Details"
                         
        
        Case "Proforma_Invoice"
            cReceiptName = "Proforma_Invoice_Trans"
            cSubRptName = "PI_Details"
            rspHeader = "rsp_Transaction_PI"
            rspDetail = "rsp_Transaction_PI_Details"
                         
        Case "Sales_Invoice"   '-------------------------This Code is for sale invoice
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Sales_Invoice_Trans"
            End If
            RepName = Empty
            cSubRptName = "SI_Details"
            rspHeader = "rsp_Transaction_Sales"
            rspDetail = "rsp_Transaction_Sales_Details"
            
        Case "Basic_Sales_Invoice"   '-------------------------This Code is for sale invoice
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "BASIC_Sales_Invoice_Trans"
            End If
            RepName = Empty
            cSubRptName = "SI_Details"
            rspHeader = "rspBasic_Transaction_Sales"
            rspDetail = "rspBasic_Transaction_Sales_Details"
         '---------------------------------------------------------------------------------
         
        Case "COMMERCIAL_Invoice"
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Commercial_Invoice_Trans"
            End If
            RepName = Empty
            cSubRptName = "CI_Details"
            rspHeader = "rsp_Transaction_CI"
            rspDetail = "rsp_Transaction_CI_Details"
                         
        Case "Delivery_Receipt"
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Delivery_Receipt_Trans"
            End If
            RepName = Empty
            cSubRptName = "DR_Details"
            rspHeader = "rspBasic_Transaction_DR"
            rspDetail = "rspBasic_Transaction_DR_Details"
            
            
        Case "Basic_Delivery_Receipt"
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Delivery_Receipt_Trans"
            End If
            RepName = Empty
            cSubRptName = "DR_Details"
            rspHeader = "rspBasic_Transaction_DR"
            rspDetail = "rspBasic_Transaction_DR_Details"
           
            
            
        Case "Transmittal_Report"
            cReceiptName = "Transmittal"
            rspHeader = "rsp_Transaction_Transmittal"
                         
        Case "Packing_list"
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Packing_list_Trans"
            End If
                
            cSubRptName = "PL_Details"
            rspHeader = "rsp_Transaction_PL"
            rspDetail = "rsp_Transaction_PL_Details"
                         
        Case "Gate_Pass"
            cReceiptName = "Gate_Pass_Trans"
            cSubRptName = "GP_Details"
            rspHeader = "rsp_Transaction_Gate_Pass"
            rspDetail = "rsp_Transaction_GP_Details"
        
        Case "Official_Receipt"
            cReceiptName = "Official_Receipt_Trans"
            cSubRptName = "PR_Details"
            rspHeader = "rsp_Transaction_OR"
            rspDetail = "rsp_Transaction_OR_Details"
            
        Case "Basic_Official_Receipt"
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Official_Receipt_Trans_BIR"
            End If
            RepName = Empty
            'Official_Receipt_Trans_ASC2
            'cReceiptName = "Official_Receipt_Trans_BIR"
            'cReceiptName = "Basic_Official_Receipt_Trans"
            cSubRptName = "PR_Details"
            rspHeader = "rspBasic_Transaction_OR"
            rspDetail = "rspBasic_Transaction_OR_Details"
        
        Case "Deposit_Slip"
            cReceiptName = "Deposit_Slip_Trans"
            cSubRptName = "DP_details"
            rspHeader = "rsp_Transaction_DP"
            rspDetail = "rsp_Transaction_DP_Details"
            
        Case "Basic_Deposit_Slip"
            cReceiptName = "Basic_Deposit_Slip_Trans"
            cSubRptName = "DP_details"
            rspHeader = "rspBasic_Transaction_DP"
            rspDetail = "rspBasic_Transaction_DP_Details"
      
      
        Case "Purchase_Requisition"
            cReceiptName = "Purchase_Request_Slip"
'            cSubRptName = "PurReq_Details"
            rspHeader = "rsp_Transaction_PR"
'            rspDetail = "rsp_Transaction_PR_Details"

        Case "Purchase_Order"
            cReceiptName = "Purchase_Order_Trans"
            cSubRptName = "PO_Details"
            rspHeader = "rsp_Transaction_PO"
            rspDetail = "rsp_Transaction_PO_Details"
            
        Case "Basic_Purchase_Order"
            cReceiptName = "Basic_Purchase_Order_Trans"
            cSubRptName = "PO_Details"
            rspHeader = "rspBasic_Transaction_PO"
            rspDetail = "rspBasic_Transaction_PO_Details"
                      
        Case "Warehouse_Receipt"
            cReceiptName = "Warehouse_Receipt_Trans"
            cSubRptName = "WRR_Details"
            rspHeader = "rsp_Transaction_WRR"
            rspDetail = "rsp_Transaction_WRR_Details"
            
        Case "Basic_Warehouse_Receipt"
            cReceiptName = "Basic_Warehouse_Receipt_Trans"
            cSubRptName = "WRR_Details"
            rspHeader = "rspBasic_Transaction_WRR"
            rspDetail = "rspBasic_Transaction_WRR_Details"
            
        Case "Basic_Warehouse_Receipt"
            cReceiptName = "Basic_Warehouse_Receipt_Trans"
            cSubRptName = "WRR_Details"
            rspHeader = "rspBasic_Transaction_WRR"
            rspDetail = "rspBasic_Transaction_WRR_Details"
            
        Case "Basic_Return_Slip"
            cReceiptName = "Basic_Return_Slip_Trans"
            rspHeader = "rspBasic_Transaction_Return_Slip"
            cSubRptName = "WRR_Details"
            rspDetail = "rspBasic_Transaction_Return_Slip_Details"
        
        Case "CMDM_Adjustment_Trans"
            cReceiptName = "CMDM_Adjustment_Trans"
            cSubRptName = "CMDM_Details"
            rspHeader = "rsp_Transaction_CMDM"
            rspDetail = "rsp_Transaction_CMDM_Details"
            
         Case "Basic_ARCMDM_Adjustment"
            cReceiptName = "Basic_ARCMDM_Adjustment_Trans"
            cSubRptName = "CMDM_Details"
            rspHeader = "rspBasic_Transaction_AR_Adjustment"
            rspDetail = "rspBasic_Transaction_AR_Adjustment_Details"
            
            
         Case "Basic_APCMDM_Adjustment"
            cReceiptName = "Basic_APCMDM_Adjustment_Trans"
            cSubRptName = "CMDM_Details"
            rspHeader = "rspBasic_Transaction_AP_Adjustment"
            rspDetail = "rspBasic_Transaction_AP_Details_Adjustment"
            
        Case "Transaction_CM_EWTEVAT"
            cReceiptName = "Transaction_CM_EWTEVAT"
            cSubRptName = "Transaction_CM_EWTEVAT_T"
            rspHeader = "rsp_Transaction_CM_EWTEVAT"
            rspDetail = "rsp_Transaction_CM_EWTEVAT_T"
        
        Case "Request_for_Payment"
            cReceiptName = "Request_for_Payment"
            rspHeader = "rsp_Transaction_RFP"

        Case "PullOut_Slip"
            cReceiptName = "Pullout_Slip_Trans"
            cSubRptName = "PulloutSlip_Details"
            rspHeader = "rsp_Transaction_PulloutSlip"
            rspDetail = "rsp_Transaction_PulloutSlip_Details"
            
        Case "Trip_Ticket"
            cReceiptName = "Trip_Ticket_Trans"
            cSubRptName = "Trip_Ticket_Details"
            rspHeader = "rsp_Transaction_TripTicket"
            rspDetail = "rsp_Transaction_TripTicket_Details"
            
        Case "Inventory_Transfer"
            cReceiptName = "Inventory_Transfer"
            rspHeader = "rsp_Transaction_InventoryTransfer"
            

        Case "Basic_Inventory_Transfer"
            cReceiptName = "Basic_Inventory_Transfer"
            rspHeader = "rspBasic_Transaction_InventoryTransfer"

        Case "BasicVoucher"          ' gino code
            cReceiptName = "Voucher"
            cSubRptName = "details_v"
            rspHeader = "rspBasic_Transaction_Voucher"
            rspDetail = "rspBasic_Transaction_Voucher_Details"
        '----------------------------------------------------------------
        Case "Voucher"
            cReceiptName = "Voucher_Trans"
            cSubRptName = "Voucher_Details"
            rspHeader = "rsp_Transaction_Voucher"
            rspDetail = "rsp_Transaction_Voucher_Details"

        Case "Check_Clearing"
            cReceiptName = "Check_Clearing_Trans"
            rspHeader = "rsp_Transaction_Checks"
            
        Case "Purchase_Invoice"
            cReceiptName = "PurchaseInvoice_Trans"
            cSubRptName = "PurchaseInvoice_Details"
            rspHeader = "rsp_Transaction_PurchaseInvoice"
            rspDetail = "rsp_Transaction_PurchaseInvoice_Details"
            
        Case "Basic_Purchase_Invoice"
            cReceiptName = "Basic_PurchaseInvoice_Trans"
            cSubRptName = "PurchaseInvoice_Details"
            rspHeader = "rspBasic_Transaction_PI"
            rspDetail = "rspBasic_Transaction_PI_Details"
            'cSubRptCmp = "company"
            'rspComp = "rsp_Company"
            
        Case "Basic_Journal_Entry"
            cReceiptName = "Basic_Journal_Entry_Trans"
            cSubRptName = "Basic_Journal_Entry_Details"
            rspHeader = "rspBasic_Transaction_JE"
            rspDetail = "rspBasic_Transaction_JE_Details"
            
         Case "Basic_Acknow_Official_Receipt"   ' ------------------Added
            If Trim(RepName) <> "" Then
                cReceiptName = RepName
            Else
                cReceiptName = "Basic_Acknow_Official_Receipt_Trans"
            End If
            RepName = Empty
            'cReceiptName = "Basic_Acknow_Official_Receipt_Trans"
            rspHeader = "rspBasic_Transaction_Acknowledge_receipt"
    Case "BasicSummaryExpense"
            cReceiptName = "SummaryExpense"
            cSubRptName = "SummaryExpense_Details"
            rspHeader = "rsp_Transaction_SummaryExpense"
            rspDetail = "rsp_Transaction_SummaryExpense_Details"
            
            
    End Select
        
    OpenReportRS
    
    Set rptPrint = ReportApp.OpenReport(App.Path & "\Crystal Reports\Transaction\" & cReceiptName & ".rpt")
    ' cModule = "BasicVoucher" Or
    If cModule = "Request_for_Payment" Or cModule = "Inventory_Transfer" _
            Or cModule = "Purchase_Order" Or cModule = "Purchase_Requisition" Or cModule = "Basic_Official_Receipt" _
            Or cModule = "Basic_Acknow_Official_Receipt" Then 'Or cModule = "Sales_Order" Then
        rptPrint.Database.SetDataSource rsReportHeader
    ElseIf cModule = "Check_Clearing" Then
        rptPrint.Database.SetDataSource rsReportHeader
    ElseIf cModule = "Transmittal_Report" Then
        rptPrint.Database.SetDataSource rsReportHeader
    ElseIf cModule = "Production_Order" Then
        rptPrint.Database.SetDataSource rsReportHeader
        rptPrint.OpenSubreport(cSubRptName).Database.SetDataSource rsReportDetail
        rptPrint.OpenSubreport("Prod_BM").Database.SetDataSource rsReportDetail2
'    ElseIf cModule = "Basic_Purchase_Invoice" Then '---------------Ready for Company Header
'        rptPrint.Database.SetDataSource rsReportHeader
'        rptPrint.OpenSubreport(cSubRptName).Database.SetDataSource rsReportDetail
'        rptPrint.OpenSubreport(cSubRptCmp).Database.SetDataSource rsRptCompany
    Else
        rptPrint.Database.SetDataSource rsReportHeader
        rptPrint.OpenSubreport(cSubRptName).Database.SetDataSource rsReportDetail
    End If
    
    If cModule = "Check_Clearing" Then
        With frmReportViewer.ITGReportViewer
            .ReportSource = rptPrint
            .PrintReport
            .ViewReport
            .DisplayGroupTree = False
            .DisplayTabs = False
            .DisplayBorder = False
            .EnableExportButton = False
            .EnableCloseButton = False
            .EnableGroupTree = False
            .EnableNavigationControls = False
            .EnableSearchControl = False
            .Zoom (95)
        End With
        frmReportViewer.Height = 6500
    Else
        With frmReportViewer.ITGReportViewer
            oContainer.SetUpContainer frmReportViewer, True
            .ReportSource = rptPrint
            .PrintReport
            .ViewReport
            .DisplayGroupTree = False
            .Zoom (95)
        End With

    End If
    
    'Audit trail
    UpdateLogFile cModule, cTransID, "Printed"


TheSource:
    If err.Number = -2147206461 Then 'File not found

        MsgBox "Report file '" & cReceiptName & ".rpt' not found.", vbCritical, msgTtl
    ElseIf err.Number = 3265 Then
        MsgBox err.Description
        MsgBox "Stored Procedure '" & rspHeader & "' not found.", vbCritical, msgTtl
    End If

    Set rsReportHeader = Nothing
    Set rsReportDetail = Nothing
    Set rsReportDetail2 = Nothing
    Set rsRptCompany = Nothing
    Set cmdReportHeader = Nothing
    Set cmdReportDetail = Nothing
    Set cmdReportDetail2 = Nothing
    Set cmdRptCompany = Nothing
    Set rptPrint = Nothing
    Set ReportApp = Nothing

End Sub

Sub OpenReportRS()
  
    rsReportHeader.CursorLocation = adUseClient
    rsReportDetail.CursorLocation = adUseClient
    rsReportDetail2.CursorLocation = adUseClient
    rsRptCompany.CursorLocation = adUseClient
    With cmdReportHeader
        .ActiveConnection = cn
        .CommandTimeout = 1000
        .CommandText = rspHeader
        .CommandType = adCmdStoredProc
        .Parameters("@cTranNo") = rptTransID
        If cModule = "Check_Clearing" Then
            .Parameters("@cCompID") = RepName
        ElseIf cModule = "BasicVoucher" Then
            .Parameters("@cCompID") = COID
            .Parameters("@type") = cTypeVoucher
        ElseIf cModule = "Transmittal_Report" Then
            .Parameters("@cCompID") = COID
            .Parameters("@cUserID") = sUserName
        Else
            .Parameters("@cCompID") = COID
        End If
    End With

    If cModule <> "Request_for_Payment" And cModule <> "Inventory_Transfer" And cModule <> "Check_Clearing" _
        And cModule <> "Transmittal_Report" And cModule <> "Purchase_Requisition" And cModule <> "Basic_Acknow_Official_Receipt" Then
        
        'Insert this condition if report has no subreport
        'And cModule <> "Sales_Order" Then
        
        
        With cmdReportDetail
            .ActiveConnection = cn
            .CommandTimeout = 1000
            .CommandText = rspDetail
            .CommandType = adCmdStoredProc
            .Parameters("@cTranNo") = rptTransID
            .Parameters("@cCompID") = COID
        End With
        Set rsReportDetail = cmdReportDetail.Execute()
    End If
    
    If cModule = "Production_Order" Then
        With cmdReportDetail2
            .ActiveConnection = cn
            .CommandTimeout = 1000
            .CommandText = rspDetail2
            .CommandType = adCmdStoredProc
            .Parameters("@cTranNo") = rptTransID
            .Parameters("@cCompID") = COID
        End With
        Set rsReportDetail2 = cmdReportDetail2.Execute()
    End If

'------------            Company Header             ---------------
'    If cModule = "Basic_Purchase_Invoice" Then
'        With cmdRptCompany
'            .ActiveConnection = cn
'            .CommandTimeout = 1000
'            .CommandText = rspComp
'            .CommandType = adCmdStoredProc
'            .Parameters("@cCompID") = COID
'        End With
'        Set rsRptCompany = cmdRptCompany.Execute()
'    End If
'-------------------------------------------------------------------


'    If cModule = "Transmittal_Report" Then
'        With cmdReportDetail2
'            .ActiveConnection = cn
'            .CommandTimeout = 1000
'            .CommandText = rspDetail2
'            .CommandType = adCmdStoredProc
'            .Parameters("@cTranNo") = rptTransID
'            .Parameters("@cCompID") = COID
'            .Parameters("@cUserName") = sUserName
'        End With
'        Set rsReportHeader = cmdReportHeader.Execute()
'    End If
    
    Set rsReportHeader = cmdReportHeader.Execute()

End Sub


